package com.lpf.json.fastjson.SerializeFilter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.AfterFilter;

public class TestAfterFilter {

	public static void main(String[] args) {
		User user = new User();
		user.setId(9L);
		user.setName("挖坑埋你");

		String jsonString = JSON.toJSONString(user); // 序列化的时候传入filter
		System.out.println("普通序列化：" + jsonString + "\n");

		AfterFilter filter = new AfterFilter() {

			@Override
			public void writeAfter(Object object) {

				User user = (User) object;
				System.out.println("------------User.id=" + user.getId() + " " + "User.name=" + user.getName() + "\n");
				user.setName(user.getName() + "$$$");
			}
		};

		jsonString = JSON.toJSONString(user, filter); // 序列化的时候传入filter
		System.out.println("AfterFilter序列化：" + jsonString + "\n");
		System.out.println(user);
	}

}
